// JavaScript Document

// Initial Value for Delay
function opacity_process() {
	this.count = 0;
	this.direct = 1;
	this.type = 1;
	this.length = 100;
	this.stoptime = 80;
	this.swaptime = 80;
	this.swapdelay = 15000;
	this.swapcount = 20;
	this.swapimg = null;
	this.showimg = null;
	this.element = "";
	this.target = null;
	this.timer = null;
	this.handler = null;
	this.loaded = false;
	//
	this.start = function(element) {
		this.element = element;
		this.target = $E(this.element);
		this.processFilter();
	};
	this.swap = function(element, delay) {
		if( delay > 0 ) {
			this.count = this.count - this.length * 2;
		}
		this.element = element;
		this.target = $E(this.element);
		this.preloadimage();
		this.processFilter();
	};
	this.processFilter = function() {
		this.count++;
		//$E("debug").innerHTML = this.count + " ";
		if( this.count >= this.swaptime && this.swaptime > 0 ) {
			this.count = this.swapcount;
			var d = this.direct;
			this.direct = 0 - this.direct;
			if( this.direct > 0 ) {
				var _obj = this;
				this.timer = window.setTimeout(function() {_obj.processFilter();}, this.swapdelay);
			} else {
				if( this.target.src == this.swapimg.src ) {
					this.target.src = this.showimg.src;
				} else {
					this.target.src = this.swapimg.src;
				}
				this.processFilter();
			}
			if( this.handler != null && typeof(this.handler) == "function" ) {
				this.handler();
			}
		} else if( this.count >= this.stoptime && this.stoptime > 0 ) {
			if( this.timer ) {
				window.clearTimeout(this.timer);	
			}
			this.processJump();
			//For Back, Fail
			if( IS_IE ) {
				//this.target.style.filter = "alpha(opacity=" + 100 + ")";
			} else if( IS_MOZILLA ) {
				//this.target.style.MozOpacity = 1;
			}
		} else if( this.type == 1 ) {
			if( IS_IE && this.count > 0 ) {
				// From 0 to 100;
				if( this.direct > 0 ) {
					this.target.style.filter = "alpha(opacity=" + (this.length - this.count) + ")";
				} else {
					this.target.style.filter = "alpha(opacity=" + (this.count) + ")";
				}
			} else if( IS_MOZILLA && this.count > 0 ) {
				// Form 0 to 1
				if( this.direct > 0 ) {
					this.target.style.MozOpacity = (1 - this.count/this.length);
				} else {
					this.target.style.MozOpacity = this.count/this.length;
				}
			}
			var _obj = this;
			this.timer = window.setTimeout(function() {_obj.processFilter();}, 50);
		} else if( this.type == 2 ) {
			var _obj = this;
			this.timer = window.setTimeout(function() {_obj.processFilter();}, 50);
		}
	};
	this.processOver = function() {
		if( this.count <= 10 ) {
			return false;
		}
		if( IS_IE ) {
			this.target.style.filter = "alpha(opacity=" + 100 + ")";
		} else if( IS_MOZILLA ) {
			this.target.style.MozOpacity = 1;
		}
		var _obj = this;
		this.timer = window.setTimeout(function() {_obj.processJump();}, 3000);
	};
	this.processJump = function () {
		//document.location.href = "home.php";
	};
	this.preloadimage = function() {
		if( this.loaded == true ) {
			return false;	
		}
		this.showimg = new Image();
		this.showimg.src = this.target.src;
		var src = this.target.src;
		var srcp = src.lastIndexOf(".");
		var srcs = src.substring(0, srcp)+'_s'+src.substring(srcp);
		this.swapimg = new Image;
		this.swapimg.src = srcs;
		var _obj = this;
		this.swapimg.onload = function(){
			_obj.loaded = true;
		};
	};
}
